package com.emoriarty.android.outilsresources.lists.statesselector;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.emoriarty.android.outilsresources.R;
import com.emoriarty.android.outilsresources.common.PlanetsAdapter;

public class PlanetsListFragment extends ListFragment {
	private View lastSelectedItem;
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		String[] planets = getResources().getStringArray(R.array.planets);
		ArrayAdapter<String> menuAdapter = new PlanetsAdapter(getActivity(), planets, android.R.layout.simple_list_item_2);
		setListAdapter(menuAdapter);
	}
	
	@Override
	public void onListItemClick (ListView l, View v, int position, long id) {
		if (lastSelectedItem != null)
			lastSelectedItem.setBackgroundResource(R.drawable.states_list_selector);
		v.setBackgroundResource(R.drawable.states_list_selected);
		lastSelectedItem = v;
	}
	
	@Override
	public void onResume() {
		super.onResume();
		getListView().setSelector(R.drawable.states_list_selector);
//		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
	}
	
	
	
}
